package com.dyw.spzx.manager.controller;

import com.dyw.spzx.manager.service.ProductService;
import com.dyw.spzx.model.dto.product.ProductDto;
import com.dyw.spzx.model.entity.product.Product;
import com.dyw.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "商品接口")
@RestController
@RequestMapping("/admin/product/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @Operation(summary = "分页查询商品列表")
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<Product>> findByPage(@PathVariable("page") Integer page,
                                                @PathVariable("limit") Integer limit,
                                                ProductDto productDto) {
        PageInfo<Product> productPageInfo = productService.findByPage(page, limit, productDto);
        return Result.ok(productPageInfo);
    }

    @Operation(summary = "保存商品")
    @PostMapping("/save")
    public Result save(@RequestBody Product product) {
        productService.save(product);
        return Result.ok(null);
    }

    @Operation(summary = "根据id查询商品详情")
    @GetMapping("/getById/{id}")
    public Result<Product> getById(@PathVariable Long id) {
        Product product = productService.getById(id);
        return Result.ok(product) ;
    }

    @Operation(summary = "保存修改商品")
    @PutMapping("updateById")
    public Result updateById(@Parameter(name = "product",description = "请求参数实体类",required = false)
                             @RequestBody Product product) {
        productService.updateById(product);
        return Result.ok(null);
    }

    @Operation(summary = "根据ID删除商品")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@Parameter(name = "id", description = "商品id", required = true) @PathVariable Long id) {
        productService.deleteById(id);
        return Result.ok(null) ;
    }

    @Operation(summary = "商品审核")
    @GetMapping("/updateAuditStatus/{id}/{auditStatus}")
    public Result updateAuditStatus(@PathVariable("id") Long id, @PathVariable("auditStatus") Integer auditStatus) {
        productService.updateAuditStatus(id, auditStatus);
        return Result.ok(null) ;
    }

    @Operation(summary = "商品上下架")
    @GetMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Long id,@PathVariable Integer status){
        productService.updateStatus(id,status);
        return Result.ok(null);
    }



}
